package com.springboot.frame.comm.database;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;
import javax.sql.DataSource;

/**
 * @author madman
 */
public class SimpleDatasource implements DataSource {

  /**
   * 驱动连接的URL
   */
  private String url;
  /**
   * 数据库连接用户名
   */
  private String username;
  /**
   * 数据库连接密码
   */
  private String password;


  public SimpleDatasource(String driverClassName, String url, String username, String password) {
    try {
      Class.forName(driverClassName);
      this.url = url;
      this.username = username;
      this.password = password;
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
  }

  @Override
  public Connection getConnection() throws SQLException {
    return DriverManager.getConnection(url, username, password);
  }

  @Override
  public Connection getConnection(String username, String password) throws SQLException {
    return DriverManager.getConnection(url, username, password);
  }

  @Override
  public <T> T unwrap(Class<T> iface) throws SQLException {
    return null;
  }

  @Override
  public boolean isWrapperFor(Class<?> iface) throws SQLException {
    return false;
  }

  @Override
  public PrintWriter getLogWriter() throws SQLException {
    return null;
  }

  @Override
  public void setLogWriter(PrintWriter out) throws SQLException {

  }

  @Override
  public int getLoginTimeout() throws SQLException {
    return 0;
  }

  @Override
  public void setLoginTimeout(int seconds) throws SQLException {

  }

  @Override
  public Logger getParentLogger() throws SQLFeatureNotSupportedException {
    return null;
  }

}
